<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.mongodb.client.MongoCursor,org.bson.Document" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>课程班列表</title>
</head>
<body>
	<jsp:include page="../navbar.html" />
	<div class="container-fluid">
		<div class="row">
			<div class="pull-right" style="margin-right:20px">
				<a href="addcourseclass.jsp">
					<button type="button" class="btn btn-default"><em class="fa fa-plus"></em> 手动添加</button>
				</a>
			</div>
			<div class="col-md-4 pull-right">
				<form action="/jspbighomework/manager/userManage/UploadServlet" method="post" enctype="multipart/form-data" name="form1" id="form1"  onsubmit="return validate()">
       				<a href="javascript:;" class="file">Excel表格导入
				     	<input type="file" name="file" />
				  	</a>
		            <span class="showFileName">
		             	未选择任何文件
		            </span>
      				<input type="hidden" name="courseclass">
      				<input type="submit" class="btn btn-primary" name="Submit" value="确定" />
  				</form>
			</div>
		</div>
		<div class="row mt20">
			<div class="col-md-12">
				<div class="panel">
                	<div class="panel-body">
                  		<h4 class="page-header mt0">课程班信息列表
                  			<div class="pull-right col-md-4" style="margin-top:-10px">
								<form action="managercourseclassServlet" method="post" class="form-horizontal">
									<div class="input-group">
								       <input class="form-control radius-clear" type="text" name="value" value="<%=request.getAttribute("queryvalue")==null?"":request.getAttribute("queryvalue") %>" placeholder="搜素" style="width:70%;" />
								       <select class="form-control" style="width:30%;" name="name">
								          <option value="name" <%="name".equals(request.getAttribute("queryname"))?"selected":"" %>>课程名称</option>
								          <option value="teachername" <%="teachername".equals(request.getAttribute("queryname"))?"selected":"" %>>教师姓名</option>
								          <option value="class" <%="class".equals(request.getAttribute("queryname"))?"selected":"" %>>教学班</option>
								       </select>								 
								       <span class="input-group-btn">
								          <button class="btn btn-default" type="submit" name="method" value="managerquery">
								             <strong><em class="fa fa-search"></em></strong>
								          </button>
								       </span>
								    </div>
								</form>
							</div>
                  		</h4>
                  		</h4>
                  		<table class="table table-hover table-bordered">
					    	<tr class="text-center">
					      		<th width="5%">序号</th>
								<th width="5%">课程班代码</th>
								<th width="5%">课程班名称</th>
								<th width="5%">教学班</th>
								<th width="5%">教师姓名</th>
								<th width="5%">教师工号</th>
								<th width="5%">职称</th>
								<th width="5%">人数</th>
								<th width="5%">考核方式</th>
								<th width="5%">起止周</th>
								<th width="5%">学时</th>
								<th width="5%">总学时</th>
								<th width="5%">周学时</th>
								<th width="5%">学分</th>
								<th width="5%">理论课时</th>
								<th width="5%">实验课时</th>
								<th width="5%">学年</th>
								<th width="5%">学期</th>
								<th width="10%">操作</th>
					    	</tr>
					    	<% MongoCursor<Document> courseclasslist = (MongoCursor<Document>)request.getAttribute("result");
								int index = 0;
								while(courseclasslist.hasNext()) {
									Document document = courseclasslist.next();%>
									<tr>
							    	    <td><%=++index %></td>
							    		<td><%=document.getString("coursecode") %></td>
							    		<td><%=document.getString("name") %></td>
							    		<td><%=document.getString("class") %></td>
							    		<td><%=document.getString("teachername") %></td>
							    		<td><%=document.getString("teachercode") %></td>
							    		<td><%=document.getString("title") %></td>
							    		<td><%=document.getString("number") %></td>
							    		<td><%=document.getString("testtype") %></td>
							    		<td><%=document.getString("beginendweek") %></td>
							    		<td><%=document.getString("studytime") %></td>
							    		<td><%=document.getString("allstudytime") %></td>
							    		<td><%=document.getString("weekstudytime") %></td>
							    		<td><%=document.getString("credit") %></td>
							    		<td><%=document.getString("theortytime") %></td>
							    		<td><%=document.getString("labtime") %></td>
							    		<td><%=document.getString("year") %></td>
							    		<td><%=document.getString("semester") %></td>
							    		<td>
							    			<a href="updateCourseClass.jsp?_id=<%=document.getObjectId("_id")%>">
												<button type="button" class="btn btn-warning" data-toggle="tooltip" data-placement="top" title="修改" ><em class="fa fa-pencil-square-o"></em></button>
											</a>
											<a href="managercourseclassServlet?_id=<%=document.getObjectId("_id") %>&method=delete">
												<button type="button" class="btn btn-danger" data-toggle="tooltip" data-placement="top" title="删除"><em class="fa fa-trash"></em></button>
											</a>					    												
							    		</td>
							    	</tr>	
							<% } %>
						</table>
                  	</div>
                  </div>
            </div>
         </div>
	</div>
	<script type="text/javascript">
	function validate() {
		var form = form1.file.value;
        if (form == "") {
      	  swal("没有选择文件","请选择要上传的文件", "warning");
            return false;
        }
        else if(form.substring(form.lastIndexOf(".")+1,form.length)!="xls" &&
      		  form.substring(form.lastIndexOf(".")+1,form.length)!="xlsx") {
      	  swal("文件格式不正确","请上传Excel表格", "warning");
      	  return false;
        }
        return true;
	}
	$(document).ready(function() {
		  $(".file").on("change","input[type='file']",function(){
			    var filePath=$(this).val();
			    if(filePath.substring(filePath.lastIndexOf(".")+1,filePath.length)=="xls" || 
			    		filePath.substring(filePath.lastIndexOf(".")+1,filePath.length)=="xlsx"){
			        var arr=filePath.split('\\');
			        var fileName=arr[arr.length-1];
			        $(".showFileName").text(fileName);
			    }else if(filePath==null || filePath==""){
			        $(".showFileName").text("未选择任何文件");
			        return false; 
			    }else {
			    	$(".showFileName").text("文件类型不正确");
			        return false;
			    }
			})	     
	})
	$(function () { $("[data-toggle='tooltip']").tooltip(); });
	</script>
</body>
</html>